import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter_module/common/extensions/cached_network_image_extension.dart';
import 'package:flutter_module/common/extensions/string_extension.dart';

class ServiceProviderItemHeader extends StatelessWidget {
  final String title;
  final Widget? right;
  final EdgeInsetsGeometry? padding;
  final void Function()? onTap;
  const ServiceProviderItemHeader(
      {Key? key,
      required this.title,
      this.right,
      this.padding = const EdgeInsets.only(
          left: 16.0, right: 16.0, top: 10.0, bottom: 12.0),
      this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        padding: padding,
        color: CupertinoColors.white,
        width: double.infinity,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: 14.0,
                fontWeight: FontWeight.bold,
              ),
            ),
            if (right != null) right!,
          ],
        ),
      ),
      onTap: onTap,
    );
  }
}

class ServiceProviderCaseItem extends StatelessWidget {
  final String? imgUrl;
  final String title;
  final void Function()? onDelete;
  final void Function()? onEdit;
  final void Function()? onTouch;
  ServiceProviderCaseItem(
      {Key? key,
      required this.title,
      this.imgUrl,
      this.onDelete,
      this.onEdit,
      this.onTouch})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: Stack(
              children: [
                GestureDetector(
                  onTap: onTouch,
                  child: ClipRRect(
                    child: SizedBox.expand(
                      child: YFNetworkImage(
                        fit: BoxFit.cover,
                        resource: imgUrl,
                        placeholderName: ImagePlaceholder.smallPlaceholder,
                      ),
                    ),
                    borderRadius: BorderRadius.circular(5.0),
                  ),
                ),
                Align(
                  child: SizedBox(
                    width: 21.0,
                    height: 21.0,
                    child: TextButton(
                      style: TextButton.styleFrom(
                        padding: EdgeInsets.zero,
                        splashFactory: NoSplash.splashFactory,
                      ),
                      onPressed: onDelete,
                      child: Image.asset(
                        'images/service_provider/service_provider_case_delete.png',
                      ),
                    ),
                  ),
                  alignment: Alignment.topRight,
                ),
                Positioned(
                  child: SizedBox(
                    width: 43.0,
                    height: 31.0,
                    child: TextButton(
                      style: TextButton.styleFrom(
                        padding: EdgeInsets.zero,
                        splashFactory: NoSplash.splashFactory,
                      ),
                      onPressed: onEdit,
                      child: Image.asset(
                        'images/service_provider/service_provider_edit_btn.png',
                      ),
                    ),
                  ),
                  left: 12.0,
                  bottom: 12.0,
                )
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.only(left: 11.0, right: 11.0, top: 8.0),
            child: Text(
              title.insertedZeroWidthSpaces(),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              textAlign: TextAlign.start,
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: 12.0,
                fontWeight: FontWeight.w800,
              ),
            ),
          )
        ],
      ),
    );
  }
}
